import { d_uniShowToast } from '../misc';

export const imageMixin = {
  data() {
    return {
      title: 'choose/previewImage',
      imageList: [],
      sourceTypeIndex: 2,
      sourceType: ['拍照', '相册', '拍照或相册'],
      sizeTypeIndex: 2,
      sizeType: ['压缩', '原图', '压缩或原图'],
      countIndex: 8,
      count: [1, 2, 3, 4, 5, 6, 7, 8, 9],

      // uView 图片上传 data ,START
      action: 'http://www.tp5.com',
      // 预置上传列表
      fileList: [],
      // fileList: [{
      // 	url: 'http://pics.sc.chinaz.com/files/pic/pic9/201912/hpic1886.jpg',
      // 	error: false,
      // 	progress: 100
      // }],

      showUploadList: true,
      customBtn: false, // 个性化上传按钮?
      autoUpload: false,
      showProgress: true,
      deletable: true,
      customStyle: false,
      maxCount: 3,
      uploadedPhotoList: [], // 组件内部的图片文件列表
      // uView 图片上传 data ,END
    };
  },
  methods: {
    reUpload() {
      this.$refs.uUpload.reUpload();
    },
    clear() {
      this.$refs.uUpload.clear();
    },
    autoUploadChange(index) {
      this.autoUpload = index === 0;
    },
    controlChange(index) {
      if (index == 0) {
        this.showProgress = true;
        this.deletable = true;
      } else {
        this.showProgress = false;
        this.deletable = false;
      }
    },
    maxCountChange(index) {
      this.maxCount = index == 0 ? 1 : index == 1 ? 2 : 4;
    },
    customStyleChange(index) {
      if (index == 0) {
        this.showUploadList = false;
        this.customBtn = true;
      } else {
        this.showUploadList = true;
        this.customBtn = false;
      }
    },
    upload() {
      this.$refs.uUpload.upload();
    },
    deleteItem(index) {
      this.$refs.uUpload.remove(index);
    },
    onOversize(file, lists) {
      // console.log('onOversize', file, lists);
    },
    onPreview(url, lists) {
      // console.log('onPreview', url, lists);
    },
    onRemove(index, lists) {
      // console.log('onRemove', index, lists);
    },
    onSuccess(data, index, lists) {
      // console.log('onSuccess', data, index, lists);
    },
    onChange(res, index, lists) {
      // console.log('onChange', res, index, lists);
    },
    error(res, index, lists) {
      // console.log('onError', res, index, lists);
    },
    onProgress(res, index, lists) {
      // console.log('onProgress', res, index, lists);
    },
    onUploaded(lists) {
      // console.log('onUploaded', lists);
    },
    onListChange(lists) {
      console.log('onListChange mixin: ', lists);
      this.imageList = lists;
      console.log(this.imageList);
    },
    beforeRemove(index, lists) {
      return true;
    },
    onChooseFail(e) {
      console.log(e);
      // uniShowToast({
      //   title: '最大可上传4MB的图片'
      // })
    },
  },
  computed: {},

  mounted() {},
};
